function inBook(id,param){
//	alert(id)
	var page=$('.container_cur').attr('page-data');
//	alert(page)
	//先去后台判断当前页是否满3张照片
	var pbId=$('#pbId').val();
	$.post(Think.U('WebApp/PhotoBooks/checkPageIsFull'),{page:page,pbId:pbId,photoId:id}, function(json){
//		alert(JSON.stringify(json))
		var str='';
		//第一张照片有空位
		if(json.status==1){
			//移除预留的照片
			$(param).remove();
			//数据库保存的照片并在书页上显示
			var obj={};
			obj.page=page;
			obj.photoId=id;
			obj.direction=1;
			$.post(Think.U('WebApp/PhotoBooks/photoInsertPage'),obj, function(data){
//				alert(JSON.stringify(data))
				if(data.status==1){
					str+='<div class="trim left">';
					str+='<div class="imgback_trim">';
					str+='<img src="'+WST.ROOT+'/'+json.img+'" class="img1">';
					str+='</div>';
					str+='<div class="imgzhao_trim aa">';
					str+='<div class="imgzhao_trim_top opcity"></div>';
					str+='<div class="imgzhao_trim_bot opcity yidong">';
					str+='<div class="trimImg">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_icon.png" class="img">';
					str+='</div>';
					str+='<div class="trimText">拖动微调</div>';
					str+='</div>';
					str+='<div class="imgzhao_trim_true queding" onclick="suer(this,id)">';
					str+='<div class="trimImg_true">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_carry_out_adjust_position_icon.png" class="img">';
					str+='</div>';
					str+='<div class="trimText_true">点击确定</div>';
					str+='</div>';
					str+='<div class="trim_huan huanwei" onclick="huan1(this)">';
					str+='<div class="conversionImg">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_transposition_icon.png" class="img">';
					str+='</div>';
					str+='<div class="conversionText">点击与另一图换位</div>';
					str+='</div>';
					str+='</div>';
					str+='<div class="imgzhao_initial kaishi">';
					str+='<div class="initial_huan bb" onclick="bb()"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_btn_nor.png" class="img"></div>';
					str+='<div class="imgzhao_deldete" onclick="del(this,'+json.photoId+')"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_delete_btn_nor.png" class="img"></div>';
					str+='</div></div>';
				}
				$('.container_cur').children('.container_a').append(str);
			});
		}
		else if(json.status==2){
			//移除预留的照片
			$(param).remove();
			//数据库保存的照片并在书页上显示
			var obj={};
			obj.page=page;
			obj.photoId=id;
			obj.direction=2;
			$.post(Think.U('WebApp/PhotoBooks/photoInsertPage'),obj, function(data){
//				alert(JSON.stringify(data))
				if(data.status==1){
					str+='<div class="conversion_top left">';
					str+='<div class="conversion_top_img">';
					str+='<img src="'+WST.ROOT+'/'+json.img+'" class="img1"></div>';
					str+='<div class="conversionZhao aa">';
					str+='<div class="imgzhao_conversion_top opcity"></div>';
					str+='<div class="imgzhao_conversion_bot huanwei" onclick="huan2(this)">';
					str+='<div class="conversionImg">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_transposition_icon.png" class="img"></div>';
					str+='<div class="conversionText">点击与另一图换位</div></div>';
					str+='<div class="conversion_tuo yidong1 opcity">';
					str+='<div class="conversion_tuoImg">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_icon.png" class="img">';
					str+='</div>';
					str+='<div class="trimText">拖动微调</div></div>';
					str+='<div class="conversion_true queding" onclick="suer(this,id)">';
					str+='<div class="trimImg_true">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_carry_out_adjust_position_icon.png" class="img">';
					str+='</div>';
					str+='<div class="trimText_true">点击确定</div></div></div>';
					str+='<div class="conversion_initial kaishi"><div class="conversion_huan bb" onclick="bb()">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_btn_nor.png" class="img"></div>';
					str+='<div class="conversion_deldete"  onclick="del(this,'+json.photoId+')"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_delete_btn_nor.png" class="img"></div></div></div>';
				}
				$('.container_cur').children('.container_b').append(str);
			});
		}
		else if(json.status==3){
			//移除预留的照片
			$(param).remove();
			//数据库保存的照片并在书页上显示
			var obj={};
			obj.page=page;
			obj.photoId=id;
			obj.direction=3;
			$.post(Think.U('WebApp/PhotoBooks/photoInsertPage'),obj, function(data){
//				alert(JSON.stringify(data))
				if(data.status==1){
					str+='<div class="conversion_bot left opcity">';
					str+='<div class="Conversion_top_img ">';
					str+='<img src="'+WST.ROOT+'/'+json.img+'" class="img1"></div>';
					str+='<div class="imgzhao_Conversion aa opcity">';
					str+='<div class="imgzhao_Conversion_bot huanwei"  onclick="huan3(this)">';
					str+='<div class="ConversionImg">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_transposition_icon.png" class="img"></div>';
					str+='<div class="ConversionText">点击与另一图换位</div></div>';
					str+='<div class="conversionTuo opcity yidong2">';
					str+='<div class="conversion_tuoImg daimg">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_icon.png" class="img"></div>';
					str+='<div class="trimText">拖动微调</div></div>';
					str+='<div class="Conversion_true queding" onclick="suer(this,id)">>';
					str+='<div class="trimImg_true Conversionimg_true">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_carry_out_adjust_position_icon.png" class="img"></div>';
					str+='<div class="trimText_true">点击确定</div></div></div>';
					str+='<div class="conversion_bot_initial kaishi"><div class="conversion_bot_huan bb" onclick="bb()">';
					str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_btn_nor.png" class="img"></div>';
					str+='<div class="conversion_bot_deldete"  onclick="del(this,'+json.photoId+')"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_delete_btn_nor.png" class="img"></div>';
					str+='</div></div>';
				}
				$('.container_cur').children('.container_c').append(str);
			});
		}
		else if(json.status==4){
			//如果是最後一页，就增加一页
			//先保存当前页+1的值
			var input= $('.gundong').val();
//			var page=Number(input)+1;
			localStorage.setItem('curPage',json.newPage);
			$.post(Think.U('WebApp/PhotoBooks/addPageInBook'),{newPage:json.newPage,photoId:id}, function(obj){
//				alert(JSON.stringify(obj))
				if(obj.status==1){

					location.reload()
//					var content='';
//					content+='<div class="top_container" page-data="'+json.newPage+'">';
//					content+='<div class="container_a">111</div>';
//					content+='<div class="container_b"></div>';
//					content+='<div class="container_c"></div>';
//					content+='</div>';
//					$('.top_img').append(content);
//					$('.zongshu').text(json.newPage);
//					$('.gundong').attr('max',json.newPage);
				}

			})
		}else{
			wstMsg('此页面已满');
		}


		var yiDong=[];
		var yidong = $('.yidong');
		for(var k=0;k<yidong.length;k++){
			yiDong.push(yidong[k]);
			yiDong[k].addEventListener("touchstart",start);
			yiDong[k].addEventListener("touchmove",move);
			yiDong[k].addEventListener("touchend",end);
		}

		var yiDong1=[]
		var yidong1 = $('.yidong1');
		for(var k=0;k<yidong1.length;k++){
			yiDong1.push(yidong1[k]);
			yiDong1[k].addEventListener("touchstart",start);
			yiDong1[k].addEventListener("touchmove",move);
			yiDong1[k].addEventListener("touchend",end);
		}

		var yiDong2=[]
		var yidong2 = $('.yidong2');
		for(var k=0;k<yidong2.length;k++){
			yiDong2.push(yidong2[k]);
			yiDong2[k].addEventListener("touchstart",start);
			yiDong2[k].addEventListener("touchmove",move);
			yiDong2[k].addEventListener("touchend",end);

		}
	});
}
$(function(){
	//生成照片

	var pbId=$('#pbId').val();
	$.post(Think.U('WebApp/PhotoBooks/firstCreatePhoto'),{pbId:pbId}, function(data){
//		alert(JSON.stringify(data))
		if(data.length>0){
			var str='';
			for(var i=0;i<data.length;i++){
				for(var k=0;k<data[i].length;k++){
					var photo=data[i][k];
					if(photo.inPage==i+1 && photo.direction==1){
						str+='<div class="trim left">';
						str+='<div class="imgback_trim">';
						str+='<img src="'+WST.ROOT+'/'+photo.img+'" class="img1" style="top:'+photo.top+';left:'+photo.zuo+'">';
						str+='</div>';
						str+='<div class="imgzhao_trim aa">';
						str+='<div class="imgzhao_trim_top opcity"></div>';
						str+='<div class="imgzhao_trim_bot opcity yidong">';
						str+='<div class="trimImg">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_icon.png" class="img">';
						str+='</div>';
						str+='<div class="trimText">拖动微调</div>';
						str+='</div>';
						str+='<div class="imgzhao_trim_true queding" onclick="suer(this,'+photo.photoId+')">';
						str+='<div class="trimImg_true">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_carry_out_adjust_position_icon.png" class="img">';
						str+='</div>';
						str+='<div class="trimText_true">点击确定</div>';
						str+='</div>';
						str+='<div class="trim_huan huanwei" onclick="huan1(this)">';
						str+='<div class="conversionImg">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_transposition_icon.png" class="img">';
						str+='</div>';
						str+='<div class="conversionText">点击与另一图换位</div>';
						str+='</div>';
						str+='</div>';
						str+='<div class="imgzhao_initial kaishi">';
						str+='<div class="initial_huan bb" onclick="bb()"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_btn_nor.png" class="img"></div>';
						str+='<div class="imgzhao_deldete" onclick="del(this,'+photo.photoId+')"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_delete_btn_nor.png" class="img"></div>';
						str+='</div></div>';
						$('.top_container').eq(i).children('.container_a').append(str);
						str='';
					}
					else if(photo.inPage==i+1 && photo.direction==2){
						str+='<div class="conversion_top left">';
						str+='<div class="conversion_top_img">';
						str+='<img src="'+WST.ROOT+'/'+photo.img+'" class="img1" style="top:'+photo.top+';left:'+photo.zuo+'"></div>';
						str+='<div class="conversionZhao aa">';
						str+='<div class="imgzhao_conversion_top opcity"></div>';
						str+='<div class="imgzhao_conversion_bot huanwei" onclick="huan2(this)">';
						str+='<div class="conversionImg">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_transposition_icon.png" class="img"></div>';
						str+='<div class="conversionText">点击与另一图换位</div></div>';
						str+='<div class="conversion_tuo yidong1 opcity">';
						str+='<div class="conversion_tuoImg">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_icon.png" class="img">';
						str+='</div>';
						str+='<div class="trimText">拖动微调</div></div>';
						str+='<div class="conversion_true queding" onclick="suer(this,'+photo.photoId+')">';
						str+='<div class="trimImg_true">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_carry_out_adjust_position_icon.png" class="img">';
						str+='</div>';
						str+='<div class="trimText_true">点击确定</div></div></div>';
						str+='<div class="conversion_initial kaishi"><div class="conversion_huan bb" onclick="bb()">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_btn_nor.png" class="img"></div>';
						str+='<div class="conversion_deldete"  onclick="del(this,'+photo.photoId+')"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_delete_btn_nor.png" class="img"></div></div></div>';
						$('.top_container').eq(i).children('.container_b').append(str);
						str='';
					}
					else if(photo.inPage==i+1 && photo.direction==3){
						str+='<div class="conversion_bot left opcity">';
						str+='<div class="Conversion_top_img ">';
						str+='<img src="'+WST.ROOT+'/'+photo.img+'" class="img1" style="top:'+photo.top+';left:'+photo.zuo+'"></div>';
						str+='<div class="imgzhao_Conversion aa opcity">';
						str+='<div class="imgzhao_Conversion_bot huanwei"  onclick="huan3(this)">';
						str+='<div class="ConversionImg">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_transposition_icon.png" class="img"></div>';
						str+='<div class="ConversionText">点击与另一图换位</div></div>';
						str+='<div class="conversionTuo opcity yidong2">';
						str+='<div class="conversion_tuoImg daimg">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_icon.png" class="img"></div>';
						str+='<div class="trimText">拖动微调</div></div>';
						str+='<div class="Conversion_true queding" onclick="suer(this,'+photo.photoId+')">>';
						str+='<div class="trimImg_true Conversionimg_true">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_carry_out_adjust_position_icon.png" class="img"></div>';
						str+='<div class="trimText_true">点击确定</div></div></div>';
						str+='<div class="conversion_bot_initial kaishi"><div class="conversion_bot_huan bb" onclick="bb()">';
						str+='<img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_adjust_position_btn_nor.png" class="img"></div>';
						str+='<div class="conversion_bot_deldete"  onclick="del(this,'+photo.photoId+')"><img src="'+WST.ROOT+'/Apps/WebApp/View/default/images/photo_book_edit_the_content_delete_btn_nor.png" class="img"></div>';
						str+='</div></div>';
						$('.top_container').eq(i).children('.container_c').append(str);
						str='';
					}
				}
			}
		}
		//图片的移动

		var _x_start,_y_start,_x_move,_y_move,_x_end,_y_end,left_start,top_start;

		//监听多个，相同的类
		var yiDong=[];
		var yidong = $('.yidong');
		for(var k=0;k<yidong.length;k++){
			yiDong.push(yidong[k]);
			yiDong[k].addEventListener("touchstart",start);
			yiDong[k].addEventListener("touchmove",move);
			yiDong[k].addEventListener("touchend",end);
		}

		var yiDong1=[]
		var yidong1 = $('.yidong1');
		for(var k=0;k<yidong1.length;k++){
			yiDong1.push(yidong1[k]);
			yiDong1[k].addEventListener("touchstart",start);
			yiDong1[k].addEventListener("touchmove",move);
			yiDong1[k].addEventListener("touchend",end);
		}

		var yiDong2=[]
		var yidong2 = $('.yidong2');
		for(var k=0;k<yidong2.length;k++){
			yiDong2.push(yidong2[k]);
			yiDong2[k].addEventListener("touchstart",start);
			yiDong2[k].addEventListener("touchmove",move);
			yiDong2[k].addEventListener("touchend",end);

		}
	})
	//跳到当前页
	var curPage=localStorage.getItem('curPage');
	var max=$('.zongshu').text();
	if(curPage==null){
		curPage=1;
	}
//	alert(curPage)
//	alert(max)
	$('.yeshu').text(curPage);
	$('.gundong').val(curPage);
	$('.top_container').eq(curPage-1).addClass('container_cur').siblings().removeClass('container_cur');
	var all=100;
	if(curPage==1){
		all=0;
	}else{
		all=(all*(curPage-1)/(max-1)).toFixed(2);
	}

	var quan=all-2.5
	//条
	$('.rangeslider__fill').css('width',all+'%');
	//圈
	$('.rangeslider__handle').css('left',quan+'%');
})